/**
 * 正式登录接口 来测试一哈
 */
import { userStore } from '@/store/userStore'
import { getCurrentInstance } from 'vue'
import { loginApi, getExperUserInfo } from '@/api/user/user'
import { LoginParm } from '@/api/user/UserModel'
import { useRouter } from 'vue-router'
export default function useLogin(loginModel: LoginParm) {
  // 这个就是一个校验和一个提交
  const store = userStore()
  const router = useRouter()
  const { proxy } = getCurrentInstance() as any
  const login = () => {
    proxy.$refs.loginFormRef.validate(async (isOk: boolean) => {
      if (isOk) {
        store.login(loginModel).then(async res => {
          console.log(res, 'useLogin---');
          if (res.code === 200) {
            // router.push('/')
            let data
            const req = await getExperUserInfo(data)
            console.log(req);
            
            if(req.code === 200) {
              sessionStorage.setItem('UserInfoList', JSON.stringify(req.data));
              store.UserInfoList = req.data
            }
            router.push({ path: '/' })
          }
        })
      }
    })
  }
  return {
    login
  }
}